An application program interface (“API”) to an application program is used to expose the functionality of the application to other programs and systems in a uniform manner. Often, it is desirable to also provide a command interface to the same functionality of the application that is exposed via the API. A command interface to an application program, as opposed to an API, is used to expose the functionality of the application to a user entering commands into a computer terminal or other user input device through which the application may be accessed. A command interface is typically supported by software that is referred to as a command line interpreter (“CLI”). Among other things, the CLI contains the logic to interpret commands received via the command interface. For example, an application for managing databases on a storage system may have an API to access functionality to carry out a backup process, such as a method to initiate the backup on the storage system and various parameters to specify the name of the database and a label to apply to the backup. A corresponding CLI might contain logic to interpret a backup command to access that same functionality to carry out the backup process via the command interface.
The CLI logic typically performs at least three core tasks. The first task is to parse and optionally error-check and/or otherwise validate the command and any arguments entered with the command. The second task is to map the parsed command and its arguments to the corresponding functionality in the application. The third task is to dispatch the command and its arguments by invoking the corresponding functionality of the application.
In some programming environments, there are techniques to automate one of the tasks of parsing, mapping, and dispatching, or to otherwise shorten the time required to develop the CLI logic for a given task. For example, in some cases programmers can at least partly automate the task of parsing or error-checking and/or otherwise validating a command received in a command interface with reusable code components. The reusable code may be obtained from a common library of reusable objects for processing a command, including parsing and validating, i.e., error-checking the syntax of the command and validating the values. The common library of reusable objects is typically stored in a library external to the specific application for which the CLI logic is being developed. An example of such an external library is described in the Apache Commons CLI (http://jakarta.apache.org/commons/cli/). While such external libraries of reusable code components may be useful, there is nothing to connect a common library to a specific application.
As another example, some programming environments may provide an external file that can be used to at least partly automate the task of mapping a command. The external file specifies the mapping of the command and argument to the corresponding functionality of the application. While such external mapping files may be helpful, they require constant manual synchronization to the functionality in the current version of the application.
Despite the availability of such techniques, there is currently no satisfactory comprehensive way to automatically perform all three of the core CLI tasks of parsing, mapping, and dispatching. As a result the CLI logic is often written entirely by hand, which is error-prone and time-consuming. As with the external files to specify mapping, hand-coded CLIs also require constant manual synchronization to the functionality in the current version of the application. For example, adding new functionality to an application having a command interface typically requires numerous modifications to the CLI, including 1) a modification of the parsing logic to accept a new command and arguments corresponding to the new functionality, 2) a modification of the mapping logic to map the new command and arguments to the new application components that carry out the new functionality, and 3) a modification of the dispatching logic to invoke the new application components when the new command is issued. Consequently, a CLI to interpret commands in a command interface to an application can be cumbersome to develop and maintain.